package com.baizhi.luoht.exception;/**
 * @Author:luoht
 * @Description：
 * @Date：Create in 14:32 2018/11/9
 */

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: SpringMVC
 * @description:
 * @author: luoht
 * @create: 2018-11-09 14:32
 **/
@Controller
@RequestMapping("/exc")
public class HerResolver implements HandlerExceptionResolver {
    @Override
    @RequestMapping("/exc1")
    public ModelAndView resolveException
            (HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
             Object o, Exception e) {
        e.printStackTrace();
        ModelAndView modelAndView = new ModelAndView();
        if (e instanceof IOException) {
            modelAndView.addObject("ex",e);
            modelAndView.setViewName("index");
        } else {
            modelAndView.addObject("ex",e);
            modelAndView.setViewName("index");
        }
        return modelAndView;
    }
}
